package com.travelbid.admin.struts.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;

import com.travelbid.admin.service.AdminUserService;




public class IsUserExistAction extends ActionSupport{
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		response.setContentType("text;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
//		String xmlOutput = "";
//		Document doc = XmlTool.createDocument("user");
//		Element result;
//		Element root = doc.getDocumentElement();

		AdminUserService service = (AdminUserService)getWebApplicationContext().getBean("AdminUserService");
		try {
			String userName = request.getParameter("userName").trim();
			if(userName == null){
			//	result = XmlTool.buildElementWithText(doc, "result", "fail");
				out.print("fail");
			}else{
				if(!service.isUserExist(userName)){
			//		result = XmlTool.buildElementWithText(doc, "result", "noReg");	
					out.print("noReg");
				}else{
			//		result = XmlTool.buildElementWithText(doc, "result", "isReg");	
					out.print("isReg");
				}
			}
		//	root.appendChild(result);
		//	xmlOutput = XmlTool.getDocumentString(doc);
		//	out.write(xmlOutput);
		}
		catch (RuntimeException  e) {
		// TODO Auto-generated catch block
			e.printStackTrace();
		//	result = XmlTool.buildElementWithText(doc, "result", "fail");
			out.print("fail");
		}
		
		
		return null;
	}

}
